package de.uni_mannheim.informatik.ai.dame_ai.util;

import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JLabel;

import de.uni_mannheim.informatik.ai.dame_ai.util.FileSystem.GameName;


@SuppressWarnings("serial")
public class LoadGameDialog extends FileAccessDialog {

	private JLabel instruction=new JLabel();
	private JButton butLoad=new MinSizeButton("Laden");
	private JButton butCancel=new MinSizeButton("Abbrechen");
	public LoadGameDialog(Window owner, GameName game, String instruction) {
		super(owner, "Spiel Laden", game);
		this.instruction.setText(instruction);
		buttonPan.add(butLoad);
		buttonPan.add(butCancel);
		this.add(new PaddedPanel(this.instruction, 10, 10), BorderLayout.NORTH);
		//buttonPan.setPreferredSize(new Dimension(5,50));
		this.add(buttonPan, BorderLayout.SOUTH);
		butLoad.addActionListener(new ActionListener() {
			@Override public void actionPerformed(ActionEvent e) {
				clickedLoad();
			}
		});
		
		butCancel.addActionListener(new ActionListener() {
			@Override public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
	}
	
	public LoadGameDialog(Window owner, GameName game) {
		this(owner, game, "Wählen Sie einen Spielstand den Sie laden möchten.");
	}
	
	private void clickedLoad(){
		int selIndex=saveList.getSelectedIndex();
		if(selIndex>=0){
			returnFile=files[selIndex];
			dispose();
		}
		else
			new MessageDialog(this, "Info", "Please select a Game first.");
	}

	public static File askForFile(Window owner, FileSystem.GameName game){
		LoadGameDialog lgd=new LoadGameDialog(owner, game);
		lgd.setVisible(true);
		return lgd.returnFile;
	}
	
	public static File askForFile(Window owner, FileSystem.GameName game, String instruction){
		LoadGameDialog lgd=new LoadGameDialog(owner, game, instruction);
		lgd.setVisible(true);
		return lgd.returnFile;
	}
}
